package com.shoujifeng.snowmusic.player;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.shoujifeng.snowmusic.player.R;
import com.shoujifeng.snowmusic.db.DatabaseUtil;
import com.shoujifeng.snowmusic.entity.Mp3Info;
import com.shoujifeng.snowmusic.player.utils.MusicPlayer;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

/**
 *本地音乐 歌手列表
 * @author luo
 *
 */
public class NativePlayerActivity extends Activity {
	private ListView listView;
	private ListAdapter mAdapter;
	private View lineLay;
	List<HashMap<String, String>> mapList;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.native_player);
		init();
	}

	public void init() {
		listView = (ListView) findViewById(R.id.native_player_list);
		listView.setDivider(null);
		lineLay = LayoutInflater.from(NativePlayerActivity.this).inflate(R.layout.line_layout, null);
		listView.addFooterView(lineLay);
		listView.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				// TODO Auto-generated method stub
				TextView playerName = (TextView) view
						.findViewById(R.id.playerName);
				Intent intent = new Intent(NativePlayerActivity.this,
						MusicByPlayerActivity.class);
				intent.putExtra("playerName", playerName.getText()
						.toString());
				startActivity(intent);
				overridePendingTransition(R.anim.right_in, R.anim.left_out);
			}
		});
		setListView();
		
	}
	private void setListView() {
		DatabaseUtil databaseUtil = new DatabaseUtil(NativePlayerActivity.this);
		mapList = new ArrayList<HashMap<String, String>>();
		mapList =databaseUtil.queryPlayerName();
		mAdapter = new SimpleAdapter(this, mapList, R.layout.native_player_list,
				new String[] { "playerName" }, new int[] { R.id.playerName });
		listView.setAdapter(mAdapter);
	}
}
